%{
#include <stdio.h>
#include <string.h>

#include "parse_job.h"

#ifdef DEBUG
#define dbg_flag 1
#else
#define dbg_flag 0
#endif

int yylex();
YYSTYPE yylval;

%}

%option noyywrap nounput

%x      QSTRING

%%
[ \t\r\n\f]*            {
                                /* Skip the white spaces... */
                        }

^"#".*$                 {
                                /* Skip shell-style single line comments... */
                        }
"*".*$                  {
                                /* Skip '*' style single line comments... */
                        }
"<<"[^>]*">>"           {
                                /* Skip angular bracket comments... */
                        }
\"                      {       /* Starting a quoted string... */
                                BEGIN(QSTRING);
                        }
<QSTRING>([^"\\]*(\\.[^"\\]*)*)\" { /* Matching the quoted string... */
                                BEGIN(INITIAL); /* End the quoted (") string... */
                                yytext[yyleng-1]='\0';
                                yyleng--;
				yylval.string = strdup(yytext);
                                if(dbg_flag) printf("tok_QSTRING<%s>\n", yytext);
                                return TOK_QSTRING;
                        }
\#                      {
                                if(dbg_flag) printf("tok_POUND ");
                                return TOK_POUND;
                        }
"$jobs"                 {
                                if(dbg_flag) printf("<tok_JOBS>\n");
                                return TOK_JOBS;
                        }
"scriptname"            {
                                if(dbg_flag) printf("tok_SCRIPTNAME ");
                                return TOK_SCRIPTNAME;
                        }
"docommand"             {
                                if(dbg_flag) printf("tok_DOCOMMAND ");
                                return TOK_DOCOMMAND;
                        }
"streamlogon"           {
                                if(dbg_flag) printf("tok_STREAMLOGON ");
                                return TOK_STREAMLOGON;
                        }
"description"           {
                                if(dbg_flag) printf("tok_DESCRIPTION ");
                                return TOK_DESCRIPTION;
                        }
"tasktype"              {
                                if(dbg_flag) printf("tok_TASKTYPE ");
                                return TOK_TASKTYPE;
                        }
"interactive"           {
                                if(dbg_flag) printf("tok_INTERACTIVE ");
                                return TOK_INTERACTIVE;
                        }
"rccondsucc"            {
                                if(dbg_flag) printf("tok_RCCONDSUCC ");
                                return TOK_RCCONDSUCC;
                        }
"recovery"              {
                                if(dbg_flag) printf("tok_RECOVERY ");
                                return TOK_RECOVERY;
                        }
"stop"                  {
                                if(dbg_flag) printf("tok_STOP ");
                                return TOK_STOP;
                        }
"continue"              {
                                if(dbg_flag) printf("tok_CONTINUE ");
                                return TOK_CONTINUE;
                        }
"rerun"                 {
                                if(dbg_flag) printf("tok_RERUN ");
                                return TOK_RERUN;
                        }
"after"                 {
                                if(dbg_flag) printf("tok_AFTER ");
                                return TOK_AFTER;
                        }
"abendprompt"           {
                                if(dbg_flag) printf("tok_ABENDPROMPT ");
                                return TOK_ABENDPROMPT;
                        }
[^ #\"\t\r\n\f]+   {
                                /* Matching any other character... trnf */
                                if(dbg_flag) printf("tok_STRING[%s]\n", yytext);
				yylval.string = strdup(yytext);
                                return TOK_STRING;
                        }

%%

#ifdef TESTSCAN
int main(int argc, char *argv[])
{
    if (argc > 1) {
        yyin = fopen(argv[1], "r");
        fprintf(stderr, "info:%s:using input file '%s'\n", argv[0], argv[1]);
    } else {
        yyin = stdin;
        fprintf(stderr, "info:%s:using standard input file\n", argv[0]);
    }
    fprintf(stderr, "info:%s:starting lexer...\n", argv[0]);
    while(yylex());
    fprintf(stderr, "info:%s:lexer ended...\n", argv[0]);
    return 0;
}
#endif
